<?php

/**
 * @Author: wuchenge
 * @Date:   2022-04-08 09:52:07
 * @Email: ligui0506@126.com
 * @Descript:
 */
namespace App\Libraries;

use Parsedown;

class MarkdownDescribe
{
    /**
     * markdown 提取简介
     * @param  string $content [description]
     * @return [type]          [description]
     */
    public static function desc(string $content, int $len = 50): string
    {
        $parsedown = new Parsedown();
        $content   = $parsedown->text($content);
        $content   = strip_tags($content);

        return self::mbStr($content, $len);
    }

    public static function mbStr(string $content, int $len = 50, string $suffix = '...'): string
    {
        if (mb_strlen($content) < $len) {
            return $content;
        }

        return mb_substr($content, 0, $len - 1) . $suffix;
    }
}
